const fs = require('fs')

exports.send = (req,res) => {
    const usertype = req.query.type
    let read = async ()=>{
        return new Promise((resolve,reject)=>{
            fs.readFile(__dirname+'/sys_menu.json','utf-8',function(err,datastr){
                if(err) reject(err)
                resolve(JSON.parse(datastr))
            })
        })
    }
    (async ()=>{
        let data = await read()
        if(usertype === 'admin'){
            var totalmenu = data.basicmenu
            totalmenu.push(data.adminmenu[0])
            const result = [...totalmenu, ...data.routedata]
            res.send({menu:totalmenu,route:result})
        }else{
            const result = [...data.basicmenu, ...data.routedata]
            res.send({menu:data.basicmenu,route:result})
        }
    })()
}